找传奇、传世资源到传世资源站!

speech声控+语音播报

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

speech演示demo
speech声控+语音播报 C#语言基础-第1张 from clipboard

private void button1_Click(object sender, EventArgs e)
        {
            SRE.SetInputToDefaultAudioDevice();      //   <======= 默认的语音输入设备,你可以设定为去识别一个WAV文件。
            GrammarBuilder GB = new GrammarBuilder();
            //GB.Append("选择");
            GB.Append(new Choices(new string[] { "换色","红色", "绿色", "蓝色", "紫色", "黑色",
                "洗澡","睡觉","你好","你来了","再见","晚安","音乐","播放","停止","关闭","换图","美女","下一张","图片","二宝","狗蛋"}));
            Grammar G = new Grammar(GB);
            G.SpeechRecognized = new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized);
            SRE.LoadGrammar(G);            //SRE.RecognizeAsync(RecognizeMode.Multiple); //<======= 异步调用识别引擎,允许多次识别(否则程序只响应你的一句话)
            SRE.RecognizeAsync();
        }
        // Handle the AudioStateChanged event. 
        private void AudioStateChangedHandler(object sender, AudioStateChangedEventArgs e)
        {
            //addLogT( string.Format("当前状态 ({0}): {1}", DateTime.Now.ToString("mm:ss.f"), e.AudioState));
        }        // Handle the RecognizeCompleted event. 
        private void RecognizeCompletedHandler(object sender, RecognizeCompletedEventArgs e)
        {
            //addLogT(string.Format("识别完成 ({0}):",DateTime.Now.ToString("mm:ss.f")));            string resultText;
            if (e.Result != null) { resultText = e.Result.Text; }
            else { resultText = "<null>"; }            //Console.WriteLine(" BabbleTimeout: {0}; InitialSilenceTimeout: {1}; Result text: {2}",
            //  e.BabbleTimeout, e.InitialSilenceTimeout, resultText);
            if (e.Error != null)
            {
                Console.WriteLine(" Exception message: ", e.Error.Message);
            }          // Start the next asynchronous recognition operation. 
          ((SpeechRecognitionEngine)sender).RecognizeAsync(RecognizeMode.Single);
        }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复